package hihocode;

import java.util.Scanner;

public class Offer19Problem1 {

	private static final int MAX = 51;
	private static final int HEIGHT = 101;
	private static final int WIDTH = 501;
	
	private String[] basic = new String[MAX];
	
	private String[] carpet = new String[HEIGHT];
	
	
	public static void main(String[] args) {
		
	}
	
	public void getRes(){
		Scanner scanner = new Scanner(System.in);
		while(scanner.hasNext()){
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			int carpets = scanner.nextInt();
			scanner.nextLine();
			for(int i = 0; i < n; i++){
				basic[i] = scanner.nextLine();
			}
			for (int i = 0; i < carpets; i++) {
				int height = scanner.nextInt();
				int width = scanner.nextInt();
				for(int j = 0; j < height; j++){
					carpet[j] = scanner.nextLine();
				}
				boolean res = false;
				outer:
				//逐行判断
				for(int j = 0; j < height; j++){
					for(int cur = 0; cur < n; cur++){
						int index  = -1;
						if( (index = carpet[j].indexOf(basic[cur])) != -1){
							//先判断首部
							if(!carpet[j].substring(0, index).equals(basic[cur].substring(m - index, m))){
								res = false;
								break outer;
							}
							int curIndex = index + m;
							//判断中间部分
							while(curIndex + m <= width){
								if(!carpet[j].substring(curIndex, curIndex + m).equals(basic[cur])){
									res = false;
									break outer;
								}
								curIndex += m;
							}
							//如果还有末尾
							if(curIndex < width){
								if(!carpet[j].substring(curIndex, width).equals(basic[cur].
										substring(0, width - curIndex))){
									res = false;
									break outer;
								}
							}
						}else {
							//判断是否有相应的
						}
					}
				}
				
			}
		}
		scanner.close();
	}
}
